package com.shujia.spark.util

import java.io.StringReader
import org.wltea.analyzer.core.IKSegmenter
import org.wltea.analyzer.core.Lexeme

import scala.collection.mutable.ListBuffer

object IKUtil {

  def fit(text: String): List[String] = {

    val listBuffer = new ListBuffer[String]

    val sr = new StringReader(text)
    val ik = new IKSegmenter(sr, true)
    var lex: Lexeme = ik.next

    while (lex != null) {
      listBuffer += lex.getLexemeText
      lex = ik.next()
    }

    listBuffer.toList
  }


  def main(args: Array[String]): Unit = {

    val text = "水是有灵性，那一抹深绿一抹浅绿，最是无限柔情"

    val list: List[String] = fit(text)
    println(list)
  }

}
